import datetime
import backtrader as bt
from strategy import MyStrategy


class MyStrategy(bt.Strategy):
    def next(self):
        print(self.datas[0].close[0]) #Print close prices


# 初始化Cerebro引擎
cerebro = bt.Cerebro()

#设置数据参数并添加至Cerebro引擎
data = bt.feeds.YahooFinanceCSVData(
    dataname='TSLA.csv',
    fromdate=datetime.datetime(2016, 1, 1),
    todate=datetime.datetime(2016, 12, 31))

cerebro.adddata(data)

# 向Cerebro引擎添加策略
cerebro.addstrategy(MyStrategy)

#运行Cerebro引擎
cerebro.run()
